package 华为OD机试B卷复用题.基础题;

import utils.MyUtil;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class HJ69_5键键盘的输出 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/基础题/input/69.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    static void Solution(Scanner in) {
        String[] sArray =  in.nextLine().split(" ");
        int res = 0,copy = 0;
        boolean isSelected = false;
        for (String s : sArray) {
            if (s.equals("1")) {
                if (isSelected) {
                    res = 1;
                    isSelected = false;
                } else {
                    res++;
                }
            }
            if(s.equals("2")){
                copy = res;
            }
            if(s.equals("3")){
                copy = res;
                res = 0;
            }
            if(s.equals("4")){
                if(isSelected){
                    res = copy;
                    isSelected = false;
                }else {
                    res += copy;
                }
            }
            if (s.equals("5")) {
                isSelected = true;
            }
        }
        System.out.println(res);
    }
}
